﻿<?php
require_once("page.class.php");
class porez extends page{
	var $db;
	function cenovnik($get){
		$this->db = new db_functions();
		switch($get["a"]){
			case "new":
				$this->createPriceList();
				break;
			default:
				$this->browse();
				break;
		}
	}
	function createPriceList(){
		$res = $this->db->select2("SELECT art_id,art_name FROM artikli ORDER BY art_name");
		foreach($res as $v){
			$art_ids[] = $v["art_id"];
			$art_names[] = $v["art_name"];
		}
		$res = $this->db->select2("SELECT * FROM artikli_tipovi ORDER BY arttip_name");
		foreach($res as $v){
			$arttip_ids[] = $v["arttip_id"];
			$arttip_names[] = $v["arttip_name"];
		}
		$res = $this->db->select2("SELECT * FROM artikli_boje ORDER BY art_boja_code");
		foreach($res as $v){
			$artboja_ids[] = $v["art_boja_id"];
			$artboja_names[] = $v["art_boja_name"];
			$artboja_codes[] = $v["art_boja_code"];
		}
		$res = $this->db->select2("SELECT * FROM porezi ORDER BY porez_name");
		foreach($res as $v){
			$porez_ids[] = $v["porez_id"];
			$porez_names[] = $v["porez_name"];
			$porez_percs[] = $v["porez_percent"]."%";
		}
		$now = time();
		$res = $this->db->select2("SELECT * FROM kampanje WHERE kampanja_start_date<".$now." AND kampanja_end_date>".$now." ORDER BY kampanja_start_date DESC");
		foreach($res as $v){
			$kampanja_ids[] = $v["kampanja_id"];
			$kampanja_names[] = $v["kampanja_naziv"];
		}
	
		$this->assign("art_id",$art_ids);
		$this->assign("art_name",$art_names);
		$this->assign("arttip_id",$arttip_ids);
		$this->assign("arttip_name",$arttip_names);
		$this->assign("artboja_id",$artboja_ids);
		$this->assign("artboja_name",$artboja_names);
		$this->assign("artboja_code",$artboja_codes);
		$this->assign("porez_id",$porez_ids);
		$this->assign("porez_name",$porez_names);
		$this->assign("porez_perc",$porez_percs);
		$this->assign("kampanja_id",$kampanja_ids);
		$this->assign("kampanja_name",$kampanja_names);
		
		echo $this->parseTemplate("cenovnik/new.tpl");
	}
	function browse(){
		$res  = $this->db->select2("SELECT * FROM cenovnici ORDER BY cenovnik_start DESC");
		foreach($res as $v){
			$ids[] = $v["cenovnik_id"];
			$starts[] = date("d.m.Y",$v["cenovnik_start"]);
		}
		
		$this->assign("cen_id",$ids);
		$this->assign("cen_start",$starts);
		
		echo $this->parseTemplate("cenovnik/browse.tpl");
	}
}
?>